<html>
<head><meta charset="utf-8"><title>Adding a new target-dependent attribute · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html">Adding a new target-dependent attribute</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207728241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207728241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hugues de Valon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207728241">(Aug 22 2020 at 15:05)</a>:</h4>
<p>Hi all <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span> !</p>
<p>I am working on adding support in Rust for a new LLVM attribute <code>cmse_nonsecure_entry</code> that will be available on LLVM 11.</p>
<p>This attribute is made to support <em>entry functions</em>  as part of the TrustZone-M feature of Armv8-M processors. You can find more information about this attribute and TrustZone-M <a href="https://developer.arm.com/documentation/ecm0359818/latest/">here</a>.</p>
<p>I started locally hacking the compiler to implement it. Since this is another LLVM attribute, I took example from other attributes like <code>cold</code> or <code>no_mangle</code> and replicated the implementation in Rust:</p>
<ul>
<li>added a new symbol for it in so it can be referred with <code>sym::cmse_nonsecure_entry</code></li>
<li>added a new <code>CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY</code></li>
<li>setting the previous flag in <code>src/librustc_typeck/collect.rs</code> when it is seen and throwing an error if the compialtion is done for a target that does not support this attribute</li>
<li>in <code>src/librustc_codegen_llvm/attributes.rs</code>, calling the LLVM API to add the function attribute string</li>
</ul>
<p>In a small example locally that works: I can see the results of the <code>cmse_nonsecure_entry</code> attribute being applied.</p>
<p>So that's all good for me and I would be very happy to upstream this (once the <a href="https://github.com/rust-lang/rust/pull/73526">LLVM 11 upgrade</a> is on <code>master</code>) but I wanted to check here:</p>
<ol>
<li>am I doing things right? Is it OK to add a target-dependent attribute next to the target-independent ones?</li>
<li>is it ok just just make a PR for this or do I need to follow a RFC (or other) process?</li>
</ol>



<a name="207728298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207728298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207728298">(Aug 22 2020 at 15:06)</a>:</h4>
<p>If it's unstable only it seems fine to make a PR</p>



<a name="207728302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207728302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207728302">(Aug 22 2020 at 15:06)</a>:</h4>
<p>I can't help with your first question, sorry, don't know this part of the compiler</p>



<a name="207728830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207728830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hugues de Valon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207728830">(Aug 22 2020 at 15:20)</a>:</h4>
<blockquote>
<p>If it's unstable only it seems fine to make a PR</p>
</blockquote>
<p>Thanks for the answer! Shall I do anything special to "make it" unstable?</p>



<a name="207729220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207729220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207729220">(Aug 22 2020 at 15:31)</a>:</h4>
<p>not sure, but the reviewer will know</p>



<a name="207729304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207729304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hugues de Valon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207729304">(Aug 22 2020 at 15:33)</a>:</h4>
<p>cool, thanks :)</p>



<a name="207737892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207737892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207737892">(Aug 22 2020 at 19:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="332250">Hugues de Valon</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Adding.20a.20new.20target-dependent.20attribute/near/207728830">said</a>:</p>
<blockquote>
<blockquote>
<p>If it's unstable only it seems fine to make a PR</p>
</blockquote>
<p>Thanks for the answer! Shall I do anything special to "make it" unstable?</p>
</blockquote>
<p>Normally, to make an attribute unstable, you want to add a "feature gate".</p>



<a name="207737898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207737898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207737898">(Aug 22 2020 at 19:07)</a>:</h4>
<p>That will include a tracking issue for future stabilization.</p>



<a name="207766377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Adding%20a%20new%20target-dependent%20attribute/near/207766377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hugues de Valon <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Adding.20a.20new.20target-dependent.20attribute.html#207766377">(Aug 23 2020 at 10:25)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="239881">@Josh Triplett</span> <br>
It's what <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> told me to do in the <a href="https://github.com/rust-lang/rust/pull/75810">PR</a> <span aria-label="happy" class="emoji emoji-1f600" role="img" title="happy">:happy:</span> !</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>